package com.frxuexi.park2209

import android.app.NotificationManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.park2209.bus.LiveDataBus
import com.frxuexi.park2209.bus.TextMessage
import com.frxuexi.park2209.databinding.ActivityMainBinding
import com.frxuexi.park2209.fragment.HomeFragment
import com.frxuexi.park2209.fragment.MeFragment
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode


class MainActivity : AppCompatActivity() {
    lateinit var binding: ActivityMainBinding
    lateinit var data:LiveData<String>
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        EventBus.getDefault().register(this)

        // 获取 NavController
        val navController = findNavController(R.id.nav_host_fragment)
        NavigationUI.setupWithNavController(binding.nav,navController)

        /*val homeFragment = HomeFragment()
        val fragments = listOf<Fragment>(
            homeFragment,
            MeFragment()
        )*/
        LiveDataBus.with("msg").value= TextMessage("hello")
        /*binding.tab.apply {
            addTab(newTab().setText("首页").setIcon(R.drawable.baseline_home))
            addTab(newTab().setText("我的").setIcon(R.drawable.ic_action_account))
            addOnTabSelectedListener(object :OnTabSelectedListener{
                override fun onTabSelected(tab: TabLayout.Tab?) {
                    showFragment(fragments.get(tab?.position!!))
                }

                override fun onTabUnselected(tab: TabLayout.Tab?) {

                }

                override fun onTabReselected(tab: TabLayout.Tab?) {

                }

            })
        }
        showFragment(homeFragment)*/
    }
    @Subscribe(threadMode = ThreadMode.POSTING)
    fun getMsg(msg:String){
        ToastUtils.showLong(msg)
    }

    /*fun showFragment(fragment: Fragment){

        val transaction = supportFragmentManager.beginTransaction()
        transaction.replace(R.id.conView,fragment)
        transaction.commit()
    }*/
}